<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ajax
 *
 * @author hassanali
 */
class ajax extends admin_controller {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    public function load_thems_helper() {
        $_POST['file'];
        $file = $_POST['file'];



        $file_path = APPPATH . 'views/admin/helper/action/' . $file . '.php';
        if (file_exists($file_path) && is_file($file_path)) {
            $this->load->view('admin/helper/action/' . $file);
        } else {
            echo '';
        }

        // load note to all statues
        if (!in_array($file,array('create_user','create_admin','create_manager','merge','delete','delete_final','rejected','','no_trash'))) {
            $this->load->view('admin/helper/action/note');
       }
    }

    public function user_autocomplite() {
        $data = FALSE;
        $term = mysql_real_escape_string($this->input->post('term'));
        $this->db->select('username');
        $this->db->like('username', $term);
        $sql = $this->db->get_where('user');
        if ($sql->result()) {
            foreach ($sql->result() as $key => $value) {
                $data[] = $value->username;
            }
        }

        echo json_encode($data);
    }

    public function email_autocomplite() {
        $term = mysql_real_escape_string($_POST['term']);
        $this->db->select('email');
        $this->db->like('email', $term);
        $sql = $this->db->get_where('users');
        if ($sql->result()) {
            foreach ($sql->result() as $key => $value) {
                $data[] = $value->email;
            }
        }

        echo json_encode($data);
    }
    
    public function admin_alert(){
       echo json_encode(admin_alert());
    }
    
    public function rate_update(){
        $value     =  mysql_real_escape_string($_POST['total']);
        $id        =  mysql_real_escape_string($_POST['id']);
        
        $this->db->update('shipment_rate',array('total'=>$value,'update_date'=>date('Y-m-d H:i:s'),'user_update'=>$this->admin_id),array('id'=>$id));
        echo $value;
    }
    public function weight_update(){
        $id     =  mysql_real_escape_string($_POST['id']);
        $weight =  mysql_real_escape_string($_POST['weight']);
        $this->db->update('items',array('weight'=>$weight,'update_date'=>date('Y-m-d H:i:s'),'user_update'=>$this->admin_id),array('id'=>$id));
        echo $weight;
    }
}
 
?>
